#include "qprojectinformationtreewidget.h"

#include "../../libs/core/qbaseitemdelegate.h"

#include <QHeaderView>


QProjectInformationTreeWidget::QProjectInformationTreeWidget(QWidget *parent) :
    QTreeWidget(parent)
{
    this->setRootIsDecorated(false);
    this->setAlternatingRowColors(true);
    this->setFrameStyle(QFrame::NoFrame);
    this->setHeaderLabels(QStringList()<<tr("Property")<<tr("Value"));
    header()->setMovable(false);
    this->setItemDelegate(new QBaseItemDelegate);
}

void QProjectInformationTreeWidget::set_information(const QStringList &list)
{
    while(m_items.size()>list.size())
    {
        delete m_items.takeLast();
    }

    while(m_items.size()<list.size())
    {
        m_items.append(new QTreeWidgetItem(this));
    }
    QString name;
    QString value;
    QString str;
    int index;
    QTreeWidgetItem* item;
    for(int i=0;i<list.size();i++)
    {
        str=list.at(i);
        index=str.indexOf("=");
        name=str.left(index);
        value=str.mid(index+1);
        item=m_items.at(i);
        item->setText(0,name);
        item->setText(1,value);
        item->setToolTip(1,value);
    }
}
